package com.gong.yuanma.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * @author GongChang
 * @version 1.0
 * @date 2021/6/22 0022 21:42
 */

class Demo implements Callable<Integer> {


    @Override
    public Integer call() throws Exception {
        System.out.println("************come callabe");
        TimeUnit.SECONDS.sleep(2);
        return 1024;
    }
}

public class CallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> futureTask = new FutureTask<>(new Demo());

        new Thread(futureTask,"aaa").start();
        new Thread(futureTask,"bbb").start();

        System.out.println(futureTask.get());
    }
}
